package models;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import play.db.jpa.Model;

@Entity
public class Topic extends Model{

	private String topicName;
	private Date creationDate;
	private String content;
	private int commentNum;
		
	@OneToMany(mappedBy = "topic", cascade = CascadeType.ALL)
	private List<CommentTopic> commentTopicList;
	
	@ManyToOne
	private User user;
	
	@ManyToOne
	private Serie serie;
	
	
	

	public List<CommentTopic> getCommentTopicList() {
		return commentTopicList;
	}


	public void setCommentTopicList(List<CommentTopic> commentTopicList) {
		this.commentTopicList = commentTopicList;
	}


	public Topic(String topicName, Date creationDate, String content,
			int commentNum, List<CommentTopic> commentTopicList, User user,
			Serie serie) {
		super();
		this.topicName = topicName;
		this.creationDate = creationDate;
		this.content = content;
		this.commentNum = commentNum;
		this.commentTopicList = new ArrayList<CommentTopic>();
		this.user = user;
		this.serie = serie;
	}


	public Topic(String topicName, Date creationDate, String content, User user, Serie serie) {
		super();
		this.topicName = topicName;
		this.creationDate = creationDate;
		this.content = content;
		this.commentTopicList = new ArrayList<CommentTopic>();
		this.user = user;
		this.serie = serie;
		this.commentNum = commentTopicList.size();
	}


	public Topic(String topicName, Date creationDate, String content,
			List<CommentTopic> commentTopicList, User user, Serie serie) {
		super();
		this.topicName = topicName;
		this.creationDate = creationDate;
		this.content = content;
		this.commentTopicList = commentTopicList;
		this.user = user;
		this.serie = serie;
		this.commentNum = commentTopicList.size();
	}


	public Serie getSerie() {
		return serie;
	}


	


	public int getCommentNum() {
		return commentNum;
	}


	public void setCommentNum(int commentNum) {
		this.commentNum = commentNum;
	}


	public void setSerie(Serie serie) {
		this.serie = serie;
	}




	public String getTopicName() {
		return topicName;
	}

	public void setTopicName(String topicName) {
		this.topicName = topicName;
	}

	public Date getCreationDate() {
		return creationDate;
	}

	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}


	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}


	public String getContent() {
		return content;
	}


	public void setContent(String content) {
		this.content = content;
	}
	
	
	public String getFormattedDate() {
		SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm");
        String formattedDate = formatter.format(creationDate);
		return formattedDate;
	}
	
}
